package com.echo.echovividlive.controller;


import com.echo.echovividlive.domain.dto.LiveRoomPageDTO;
import com.echo.echovividlive.domain.dto.PageQueryDTO;
import com.echo.echovividlive.domain.entity.LiveRoom;
import com.echo.echovividlive.domain.entity.Result;
import com.echo.echovividlive.service.ILiveRoomService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiajunjie
 * @since 2024-11-26
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/echo/live")
public class LiveRoomController {

    private final ILiveRoomService liveRoomService;

    /**
     * 开播
     * @param liveRoom
     * @return
     */
    @PostMapping("/living")
    public Result living(@RequestBody LiveRoom liveRoom) {
        log.info("开启直播参数:{}", liveRoom);
        return liveRoomService.living(liveRoom);
    }

    /**
     * 获取直播详情
     * @param roomId
     * @return
     */
    @GetMapping("/info/{roomId}")
    public Result watch(@PathVariable Integer roomId) {
        return liveRoomService.getRoomInfoById(roomId);
    }


    /**
     * 获取直播间人数
     * @param roomId
     * @return
     */
    @GetMapping("/getCount/{roomId}")
    public Result getCount(@PathVariable Integer roomId) {
        return liveRoomService.getCountByRoomId(roomId);
    }

    /**
     * 分页查询直播列表
     * @param pageQueryDTO
     * @return
     */
    @PostMapping("/list")
    public Result list(@RequestBody LiveRoomPageDTO pageQueryDTO) {
        return liveRoomService.pageList(pageQueryDTO);
    }

    /**
     * 上传直播封面
     * @param file
     * @return
     */
    @PostMapping("/cover")
    public Result coverUpload(@RequestParam("cover") MultipartFile file) {
        return liveRoomService.uploadCover(file);
    }

    /**
     * 关播
     * @param roomId
     * @return
     */
    @GetMapping("/close/{roomId}")
    public Result close(@PathVariable Integer roomId) {
        liveRoomService.closeLiving(roomId);
        return Result.success();
    }

}
